<template>
    <div id="DefectReviewDetail">
        <div>
            <h1 class="text-success">缺陷分析详情页</h1>
        </div>
        <hr>
        <div >
            <h1 class="text-success">{{dateChange}}</h1>
        </div>

        <div class="row">
            <div class="col-lg-6">
                <DataTable :table_id="tableinfo_inflow.id" :table_title="tableinfo_inflow.title" :columns="tableinfo_inflow.columns" 
                    :table_data='tableinfo_inflow.table_data' :columns_key="tableinfo_inflow.columns_key" :columnDefs="tableinfo_inflow.columnDefs">  
                </DataTable>
            </div>
            <div class="col-lg-6">
                <DataTable :table_id="tableinfo_outflow.id" :table_title="tableinfo_outflow.title" :columns="tableinfo_outflow.columns" 
                    :table_data='tableinfo_outflow.table_data' :columns_key="tableinfo_outflow.columns_key" :columnDefs="tableinfo_outflow.columnDefs">  
                </DataTable>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <DataTable :table_id="tableinfo_seriousbug.id" :table_title="tableinfo_seriousbug.title" :columns="tableinfo_seriousbug.columns" 
                    :table_data='tableinfo_seriousbug.table_data' :columns_key="tableinfo_seriousbug.columns_key" :columnDefs="tableinfo_seriousbug.columnDefs">  
                </DataTable>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <DataTable :table_id="tableinfo_legacybug.id" :table_title="tableinfo_legacybug.title" :columns="tableinfo_legacybug.columns" 
                    :table_data='tableinfo_legacybug.table_data' :columns_key="tableinfo_legacybug.columns_key" :columnDefs="tableinfo_legacybug.columnDefs">  
                </DataTable>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <DataTable :table_id="tableinfo_deadlinebug.id" :table_title="tableinfo_deadlinebug.title" :columns="tableinfo_deadlinebug.columns" 
                    :table_data='tableinfo_deadlinebug.table_data' :columns_key="tableinfo_deadlinebug.columns_key" :columnDefs="tableinfo_deadlinebug.columnDefs">  
                </DataTable>
            </div>
        </div>
    </div>
</template>
<script>
import DataTable from '@/components/qa/DataTable.vue'
export default {
    name: 'DefectReviewDetail',
    components: {
        DataTable,
    },
    props: {
        
    },
    data() {
        return {
            dateChange: '',
            project: '',
            branch: '',
            component: '',
            tableinfo_inflow: {
                id: 'table_defect_inflow',
                title: '模块缺陷检出',
                columns: ['模块名称','S','A','B','C','D'],
                table_data: [],
                columns_key: [
                    {data: 'b_component'},
                    {data: 'count_S'},
                    {data: 'count_A'},
                    {data: 'count_B'},
                    {data: 'count_C'},
                    {data: 'count_D'}
                ],
                columnDefs: [],
            },
            tableinfo_outflow: {
                id: 'table_defect_outflow',
                title: '模块缺陷流出',
                columns: ['模块名称','S','A','B','C','D'],
                table_data: [],
                columns_key: [
                    {data: 'b_component'},
                    {data: 'count_S'},
                    {data: 'count_A'},
                    {data: 'count_B'},
                    {data: 'count_C'},
                    {data: 'count_D'}
                ],
                columnDefs: [],
            },
            tableinfo_seriousbug: {
                id: 'table_defect_seriousbug',
                title: '严重问题Highlight',
                columns: ['创建日期','提交单号','标题','版本号','模块名称','创建者', '指派给', '指派日期', '截止期限', '操作'],
                table_data: [],
                columns_key: [
                    {data: 'b_createtime'},
                    {data: 'b_number'},
                    {data: 'b_summary'},
                    {data: 'b_version'},
                    {data: 'b_component'},
                    {data: 'b_creator',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    }, 
                    {data: 'b_assigned_to',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    },
                    {data: 'b_assignedtime'},
                    {data: 'b_deadline'}
                ],
                columnDefs: [
                    {
                        targets: 9,
                        width: '10%',
                        // eslint-disable-next-line 
                        render: function(data, type, row, meta) {
                            var ticket_no = row.b_number
                            return '<a href="http://192.168.100.160/html/bugzilla/show_bug.cgi?id='+ticket_no
                                +'" class="btn btn-sm btn-primary" target="_blank">查看详情</a>';
                        }
                    }
                ],
            },
            tableinfo_legacybug: {
                id: 'table_defect_legacybug',
                title: '遗留缺陷数据',
                columns: ['创建日期','提交单号','标题','版本号','模块名称','创建者', '指派给', '指派日期', '截止期限', '操作'],
                table_data: [],
                columns_key: [
                    {data: 'b_createtime'},
                    {data: 'b_number'},
                    {data: 'b_summary'},
                    {data: 'b_version'},
                    {data: 'b_component'},
                    {data: 'b_creator',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    }, 
                    {data: 'b_assigned_to',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    },
                    {data: 'b_assignedtime'},
                    {data: 'b_deadline'}
                ],
                columnDefs: [
                    {
                        targets: 9,
                        width: '10%',
                        // eslint-disable-next-line 
                        render: function(data, type, row, meta) {
                            var ticket_no = row.b_number
                            return '<a href="http://192.168.100.160/html/bugzilla/show_bug.cgi?id='+ticket_no
                                +'" class="btn btn-sm btn-primary" target="_blank">查看详情</a>';
                        }
                    }
                ],
            },
            tableinfo_deadlinebug: {
                id: 'table_defect_deadlinebug',
                title: '超期未解决Bugs数据',
                columns: ['创建日期','提交单号','标题','版本号','模块名称','创建者', '指派给', '指派日期', '截止期限', '操作'],
                table_data: [],
                columns_key: [
                    {data: 'b_createtime'},
                    {data: 'b_number'},
                    {data: 'b_summary', width: '30%'},
                    {data: 'b_version'},
                    {data: 'b_component'},
                    {data: 'b_creator',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    }, 
                    {data: 'b_assigned_to',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    },
                    {data: 'b_assignedtime'},
                    {data: 'b_deadline'}
                ],
                columnDefs: [
                    {
                        targets: 9,
                        width: '10%',
                        // eslint-disable-next-line 
                        render: function(data, type, row, meta) {
                            var ticket_no = row.b_number
                            return '<a href="http://192.168.100.160/html/bugzilla/show_bug.cgi?id='+ticket_no
                                +'" class="btn btn-sm btn-primary" target="_blank">查看详情</a>';
                        }
                    }
                ],
            },
            
        }
    },
    created: function() {
        this.dateChange = this.$route.params.date;
        this.project = this.$route.params.pmsProjectId;
        this.branch = this.$route.params.select1;
        this.component = this.$route.params.select2;
        // console.log(param);
        // console.log(param1)
        // this.param = param;
    },
    watch: {
        "tableinfo_detail.table_data": {
            handler: function() {
                
            },
            deep: true,
        },
    },
    methods: {
        getBugSAB: function(after, before, project, branch, component) {
            this.$axios.get('/api/qa/bugsab/?after='+after+'&before='+before+'&project='+project+'&branch='+branch+'&component='+component)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.sum);
                        this.tableinfo_inflow.table_data = response.data.bugSAB_inflow;
                        this.tableinfo_outflow.table_data = response.data.bugSAB_outflow;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        getSeriousBug: function(after, before, project, branch, component) {
            this.$axios.get('/api/qa/seriousbug/?after='+after+'&before='+before+'&project='+project+'&branch='+branch+'&component='+component)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.sum);
                        this.tableinfo_seriousbug.table_data = response.data.seriousbug;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        getLegacyBug: function(after, before, project, branch, component) {
            this.$axios.get('/api/qa/legacybug/?after='+after+'&before='+before+'&project='+project+'&branch='+branch+'&component='+component)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.sum);
                        this.tableinfo_legacybug.table_data = response.data.legacybug;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        getDeadlineBug: function(after, before, project, branch, component) {
            this.$axios.get('/api/qa/deadlinebug/?after='+after+'&before='+before+'&project='+project+'&branch='+branch+'&component='+component)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.sum);
                        this.tableinfo_deadlinebug.table_data = response.data.deadlinebug;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        }
    },
    mounted: function() {
        var after = this.dateChange.substring(0,10);
        var before = this.dateChange.substring(13);
        this.getBugSAB(after, before, this.project, this.branch, this.component);
        this.getSeriousBug(after, before, this.project, this.branch, this.component);
        this.getLegacyBug(after, before, this.project, this.branch, this.component);
        this.getDeadlineBug(after, before, this.project, this.branch, this.component);
    }
}
</script>
